using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace LMSData
{
	/// <summary>
	/// Strongly-typed collection for the ResourceType class.
	/// </summary>
	[Serializable]
	public partial class ResourceTypeCollection : ActiveList<ResourceType, ResourceTypeCollection> 
	{	   
		public ResourceTypeCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the ResourceType table.
	/// </summary>
	[Serializable]
	public partial class ResourceType : ActiveRecord<ResourceType>
	{
		#region .ctors and Default Settings
		
		public ResourceType()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public ResourceType(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public ResourceType(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public ResourceType(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("ResourceType", TableType.Table, DataService.GetInstance("LMS"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarResourceTypeID = new TableSchema.TableColumn(schema);
				colvarResourceTypeID.ColumnName = "ResourceTypeID";
				colvarResourceTypeID.DataType = DbType.Int32;
				colvarResourceTypeID.MaxLength = 0;
				colvarResourceTypeID.AutoIncrement = true;
				colvarResourceTypeID.IsNullable = false;
				colvarResourceTypeID.IsPrimaryKey = true;
				colvarResourceTypeID.IsForeignKey = false;
				colvarResourceTypeID.IsReadOnly = false;
				colvarResourceTypeID.DefaultSetting = @"";
				colvarResourceTypeID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarResourceTypeID);
				
				TableSchema.TableColumn colvarTypeName = new TableSchema.TableColumn(schema);
				colvarTypeName.ColumnName = "TypeName";
				colvarTypeName.DataType = DbType.String;
				colvarTypeName.MaxLength = 250;
				colvarTypeName.AutoIncrement = false;
				colvarTypeName.IsNullable = true;
				colvarTypeName.IsPrimaryKey = false;
				colvarTypeName.IsForeignKey = false;
				colvarTypeName.IsReadOnly = false;
				colvarTypeName.DefaultSetting = @"";
				colvarTypeName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTypeName);
				
				TableSchema.TableColumn colvarCommonName = new TableSchema.TableColumn(schema);
				colvarCommonName.ColumnName = "CommonName";
				colvarCommonName.DataType = DbType.String;
				colvarCommonName.MaxLength = 250;
				colvarCommonName.AutoIncrement = false;
				colvarCommonName.IsNullable = true;
				colvarCommonName.IsPrimaryKey = false;
				colvarCommonName.IsForeignKey = false;
				colvarCommonName.IsReadOnly = false;
				colvarCommonName.DefaultSetting = @"";
				colvarCommonName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCommonName);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["LMS"].AddSchema("ResourceType",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("ResourceTypeID")]
		public int ResourceTypeID 
		{
			get { return GetColumnValue<int>("ResourceTypeID"); }

			set { SetColumnValue("ResourceTypeID", value); }

		}

		  
		[XmlAttribute("TypeName")]
		public string TypeName 
		{
			get { return GetColumnValue<string>("TypeName"); }

			set { SetColumnValue("TypeName", value); }

		}

		  
		[XmlAttribute("CommonName")]
		public string CommonName 
		{
			get { return GetColumnValue<string>("CommonName"); }

			set { SetColumnValue("CommonName", value); }

		}

		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varTypeName,string varCommonName)
		{
			ResourceType item = new ResourceType();
			
			item.TypeName = varTypeName;
			
			item.CommonName = varCommonName;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varResourceTypeID,string varTypeName,string varCommonName)
		{
			ResourceType item = new ResourceType();
			
				item.ResourceTypeID = varResourceTypeID;
				
				item.TypeName = varTypeName;
				
				item.CommonName = varCommonName;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string ResourceTypeID = @"ResourceTypeID";
			 public static string TypeName = @"TypeName";
			 public static string CommonName = @"CommonName";
						
		}

		#endregion
	}

}

